package com.theta.common.base.swagger.doc.config;


import com.github.xiaoymin.knife4j.aggre.spring.configuration.Knife4jAggregationProperties;
import com.theta.common.base.swagger.doc.core.thread.SyncThread;
import cn.hutool.json.JSONUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;



@RefreshScope
@Setter
@Getter
@Slf4j
@EnableConfigurationProperties({Knife4jAggregationProperties.class})
@Configuration
public class NacosSwaggerConfig {


    @Autowired
    private Knife4jAggregationProperties properties;
    @Value("${knife4j.nacos.serviceUrl:}")
    private String serviceUrl;
    @Value("${server.port:}")
    private String port;
    @Autowired
    private NacosExtendRepository nacosRepository;


    @PostConstruct
    public void init(){
    	//knife4j 内部代码耦合太紧，一些方法设置的为private导致无法拓展为动态加载swagger接口信息，这里改为线程异步轮询处理 10s一次从服务列表中加载swagger的配置信息
        log.info(serviceUrl+"====>"+(properties==null ||properties.getNacos()==null?"properties is null":JSONUtil.toJsonStr(properties.getNacos())));
        SyncThread t=new SyncThread(nacosRepository, properties);
        t.start();
        log.info("finish============");
    }
    
    
    
    

}
